//获取cookie
function getCookie(name) {
    // 拆分 cookie 字符串
    var cookieArr = document.cookie.split(";");
   
    // 循环遍历数组元素
    for(var i = 0; i < cookieArr.length; i++) {
        var cookiePair = cookieArr[i].split("=");
       
        /* 删除 cookie 名称开头的空白并将其与给定字符串进行比较 */
        if(name == cookiePair[0].trim()) {
            // 解码cookie值并返回
            return decodeURIComponent(cookiePair[1]);
        }
    }
    // 如果未找到，则返回null
    return null;
}

//订单初始状态
$("#daishouhuo").hide();
$("#zuyong").hide();
$("#jieshu").hide();
$("#daifahuo").hide();
$("#shouhou").hide();
$("#daiqueren_").hide();
$("#daizhifu").show();

function funcjump(params){
    //setCookie("seller",params,7);
    var obj={
        seller:params,
        user:getCookie("username"),
    
    }
    $.ajax({
        url: "http://8.130.103.251:8080/conversation/add",
        type: "POST",
        data: obj,
        contentType: 'application/json;charset=utf-8',
        success : function(){
            window.open("message.html");//跳转聊天界面
        }
    })

    
}


//切换订单状态
$(document).ready(function(){

//点击待支付
$("#five").click(function(){
    $("#two").removeClass("am-active");
    $("#three").removeClass("am-active");
    $("#four").removeClass("am-active");
    $("#one").removeClass("am-active");
    $("#five").addClass("am-active");
    $("#six").removeClass("am-active");
    //$("#five").addClass("background_color");
    $("#seven").removeClass("am-active");
    $("#daiqueren_").hide();
    $("#shouhou").hide();
    $("#daizhifu").show();
    $("#daifahuo").hide();
    $("#daishouhuo").hide();
    $("#zuyong").hide();
    $("#jieshu").hide();
    $("#five").addClass("am-animation-shake");
})

//点击待发货
$("#one").click(function(){
    // alert("执行1");
    $("#two").removeClass("am-active");
    $("#three").removeClass("am-active");
    $("#four").removeClass("am-active");
    $("#one").addClass("am-active");
    $("#five").removeClass("am-active");
    $("#six").removeClass("am-active");
    $("#seven").removeClass("am-active");
    $("#daiqueren_").hide();
    $("#shouhou").hide();
    $("#daizhifu").hide();
    $("#daifahuo").show();
    $("#daishouhuo").hide();
    $("#zuyong").hide();
    $("#jieshu").hide();
    
})

//点击待收货
$("#two").click(function(){
    // alert("执行2");
    $("#one").removeClass("am-active");
    $("#three").removeClass("am-active");
    $("#four").removeClass("am-active");
    $("#two").addClass("am-active");
    $("#five").removeClass("am-active");
    $("#six").removeClass("am-active");
    $("#seven").removeClass("am-active");
    $("#daiqueren_").hide();
    $("#shouhou").hide();
    $("#daizhifu").hide();
    $("#daishouhuo").show();
    $("#daifahuo").hide();
    $("#zuyong").hide();
    $("#jieshu").hide();
})

//点击正在租用
$("#three").click(function(){
    // alert("执行3");
    $("#one").removeClass("am-active");
    $("#two").removeClass("am-active");
    $("#four").removeClass("am-active");
    $("#three").addClass("am-active");
    $("#five").removeClass("am-active");
    $("#six").removeClass("am-active");
    $("#seven").removeClass("am-active");
    $("#daiqueren_").hide();
    $("#shouhou").hide();
    $("#daizhifu").hide();
    $("#daishouhuo").hide();
    $("#daifahuo").hide();
    $("#zuyong").show();
    $("#jieshu").hide();
})

//点击待商家确认
$("#seven").click(function(){
    $("#one").removeClass("am-active");
    $("#two").removeClass("am-active");
    $("#three").removeClass("am-active");
    $("#four").removeClass("am-active");
    $("#five").removeClass("am-active");
    $("#six").removeClass("am-active");
    $("#seven").addClass("am-active");
    $("#daiqueren_").show();
    $("#shouhou").hide();
    $("#daizhifu").hide();
    $("#daishouhuo").hide();
    $("#daifahuo").hide();
    $("#zuyong").hide();
    $("#jieshu").hide();
})

//点击已结束
$("#four").click(function(){
    // alert("执行4");
    $("#one").removeClass("am-active");
    $("#two").removeClass("am-active");
    $("#three").removeClass("am-active");
    $("#four").addClass("am-active");
    $("#five").removeClass("am-active");
    $("#six").removeClass("am-active");
    $("#seven").removeClass("am-active");
    $("#daiqueren_").hide();
    $("#shouhou").hide();
    $("#daizhifu").hide();
    $("#daishouhuo").hide();
    $("#daifahuo").hide();
    $("#zuyong").hide();
    $("#jieshu").show();
})

//点击售后
$("#six").click(function(){
    $("#one").removeClass("am-active");
    $("#two").removeClass("am-active");
    $("#three").removeClass("am-active");
    $("#four").removeClass("am-active");
    $("#five").removeClass("am-active");
    $("#six").addClass("am-active");
    $("#seven").removeClass("am-active");
    $("#daiqueren_").hide();
    $("#daizhifu").hide();
    $("#daishouhuo").hide();
    $("#daifahuo").hide();
    $("#zuyong").hide();
    $("#jieshu").hide();
    $("#shouhou").show();
})
})


//函数getDataRow用于创建行
function getDataRow(result){
    //创建行
    var row = document.createElement('tr');
    //创建第一列租物名称
    var name = document.createElement('td'); 
    name.innerHTML = result.productName; //填充数据
    row.appendChild(name); //加入行
    //创建第二列订单号
    var orderid = document.createElement('td');
    orderid.innerHTML = result.orderId;
    row.appendChild(orderid);
    //创建第三列商家
    var seller = document.createElement('td');
    var btn_chat = document.createElement('button');
    btn_chat.innerHTML = result.seller;
    seller.addEventListener("click", funcjump.bind(seller, result.seller));
    $(btn_chat).addClass("btn");
    seller.appendChild(btn_chat);
    row.appendChild(seller);
    //创建第四列租金
    var money = document.createElement('td');
    money.innerHTML = result.rental;
    row.appendChild(money); 
    //创建第五列订单创建时间
    var begintime = document.createElement('td');
    begintime.innerHTML = result.makeTime;
    row.appendChild(begintime); 
    //返回创建的行
    return row;

}


//向后端请求数据显示到订单代支付界面
window.onload =function() {  //一加载界面就调用
    var obj={
        user:getCookie("username"),
        //user:"zhangjian",
        shipStatus:"待支付",
    }
    // console.log(document.cookie);
    console.log(getCookie("username"));
    
    $.ajax({
            url: "http://8.130.103.251:8080/order/getBuyOrder",
            type: "get",
            
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(order){
                console.log(order);
                
                var tbody = document.getElementById('tbodyfive');
                //遍历后端数据  
                for(var i = 0;i < order.length; i++){ 
                //定义getDataRow方法,返回tr行数据
                var trow = getZhifuRow(order[i]); 
                    tbody.appendChild(trow);
                }
            }
        })
    }
    
//函数getZhifuRow用于创建行
function getZhifuRow(result){
    //创建行
    var row = document.createElement('tr');
    //创建第一列租物名称
    var name = document.createElement('td'); 
    name.innerHTML = result.productName; //填充数据
    row.appendChild(name); //加入行
    //创建第二列订单号
    var orderid = document.createElement('td');
    orderid.innerHTML = result.orderId;
    row.appendChild(orderid);
    //创建第三列商家
    var seller = document.createElement('td');
    var btn_chat = document.createElement('button');
    btn_chat.innerHTML = result.seller;
    seller.addEventListener("click", funcjump.bind(seller, result.seller));
    $(btn_chat).addClass("btn");
    seller.appendChild(btn_chat);
    row.appendChild(seller); 
    //创建第四列租金
    var money = document.createElement('td');
    money.innerHTML = result.rental;
    row.appendChild(money); 
    //创建第五列订单创建时间
    var begintime = document.createElement('td');
    begintime.innerHTML = result.makeTime;
    row.appendChild(begintime); 
    //创建第六列确认支付button
    var btn_one = document.createElement('td');
    var btnone = document.createElement('button');
    btnone.innerHTML = "我要付款";
    $(btnone).addClass("btn");
    btn_one.appendChild(btnone);
    row.appendChild(btn_one);
    $(btn_one).click(function(){
        //点击按钮触发事件
       
        var obj={
            orderId:orderid.innerHTML
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/order/pay",//调用确认收货
            type: "get",
            
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(result){
              window.open(result);
            }
        }) 
    
    })
    //返回创建的行
    return row;

}

//点击待支付
$(document).ready(function(){
    $("#five").click(function(){
        $("#five").addClass("am-animation-shake");
        var obj={
            user:getCookie("username"),
            //user:"zhangjian",
            shipStatus:"待支付",
        }
        // console.log(document.cookie);
        console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/order/getBuyOrder",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    var tbody = document.getElementById('tbodyfive');
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getDataRow方法,返回tr行数据
                        var trow = getZhifuRow(order[i]);
                        tbody.appendChild(trow);
                    }
                }
            })
    })
})

//点击待发货
$(document).ready(function(){
    $("#one").click(function(){
        var obj={
            user:getCookie("username"),
            //user:"zhangjian",
            shipStatus:"待发货",
        }
        // console.log(document.cookie);
        console.log(getCookie("username"));
    $.ajax({
            url: "http://8.130.103.251:8080/order/getBuyOrder",
            type: "get",
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(order){
                console.log(order);
                var tbody = document.getElementById('tbodyone');
                $(tbody).html("");
                //遍历后端数据  
                for(var i = 0;i < order.length; i++){ 
                //定义getDataRow方法,返回tr行数据
                    var trow = getDataRow(order[i]); 
                    tbody.appendChild(trow);
                }
            }
        })
    })
})

//函数getShouhuoRow用于创建含确认收货button的行
function getShouhuoRow(result){
    //创建行
    var row = document.createElement('tr');
    //创建第一列租物名称
    var name = document.createElement('td'); 
    name.innerHTML = result.productName; //填充数据
    row.appendChild(name); //加入行
    //创建第二列订单号
    var orderid = document.createElement('td');
    orderid.innerHTML = result.orderId;
    row.appendChild(orderid);
    //创建第三列商家
    var seller = document.createElement('td');
    var btn_chat = document.createElement('button');
    btn_chat.innerHTML = result.seller;
    seller.addEventListener("click", funcjump.bind(seller, result.seller));
    $(btn_chat).addClass("btn");
    seller.appendChild(btn_chat);
    row.appendChild(seller);
    //创建第四列租金
    var money = document.createElement('td');
    money.innerHTML = result.rental;
    row.appendChild(money); 
    //创建第五列订单创建时间
    var begintime = document.createElement('td');
    begintime.innerHTML = result.makeTime;
    row.appendChild(begintime); 
    //创建第六列确认收货button
    var btn_one = document.createElement('td');
    var btnone = document.createElement('button');
    btnone.innerHTML = "确认收货";
    $(btnone).addClass("btn");
    btn_one.appendChild(btnone);
    row.appendChild(btn_one);
    $(btn_one).click(function(){
        //点击按钮触发事件
        var r=confirm("确认收货");
        if(r==false){
            return;
        }else{
        var obj={
            orderId:orderid.innerHTML
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/order/shouhuo",//调用确认收货
            type: "get",
            
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(){
              alert("请点击待收货以刷新订单状态！");
            }
        }) 
    }
    })
    //返回创建的行
    return row;

}


//点击待收货
$(document).ready(function(){
    $("#two").click(function(){
        var obj={
            user:getCookie("username"),
            //user:"zhangjian",
            shipStatus:"待收货",
        }
        // console.log(document.cookie);
        console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/order/getBuyOrder",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    var tbody = document.getElementById("tbodytwo");
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getShouhuoRow方法,返回tr行数据
                        var trow = getShouhuoRow(order[i]); 
                        tbody.appendChild(trow);
                    }
                }
            })
    })
})

//函数getButtonRow用于创建含button的行  先租后买&续租&退货
function getButtonRow(result){
    //创建行
    var row = document.createElement('tr');
    
    //创建第一列租物名称
    var name = document.createElement('td'); 
    name.innerHTML = result.productName; //填充数据
    row.appendChild(name); //加入行
    //创建第二列订单号
    var orderid = document.createElement('td');
    orderid.innerHTML = result.orderId;
    row.appendChild(orderid);
    //创建第三列商家
    var seller = document.createElement('td');
    var btn_chat = document.createElement('button');
    btn_chat.innerHTML = result.seller;
    seller.addEventListener("click", funcjump.bind(seller, result.seller));
    $(btn_chat).addClass("btn");
    seller.appendChild(btn_chat);
    row.appendChild(seller);
    //创建第四列租金
    var money = document.createElement('td');
    money.innerHTML = result.rental;
    row.appendChild(money); 
    //创建第五列订单创建时间
    var begintime = document.createElement('td');
    begintime.innerHTML = result.makeTime;
    row.appendChild(begintime); 
    //创建第6列订单创建时间
    var endtime = document.createElement('td');
    endtime.innerHTML = result.returnTime;
    row.appendChild(endtime);
    console.log("am-");
    var date1 = new Date(result.makeTime);  //开始时间
    var date2 = new Date(result.returnTime);    //结束时间
    var date3 = date2.getTime() - date1.getTime();  //时间差的毫秒数
    //计算出相差天数
    var days = Math.floor(date3 / (24 * 3600 * 1000));
    console.log(days);
    if(days<3){
        //row.addClass("am-danger");
        $(row).addClass("am-danger");//添加Class
    }else{
        console.log("未到期");
    }

    
    //创建续租按钮
    var btn_five = document.createElement('td');
    var btnfive = document.createElement('button');
    btnfive.innerHTML = "续租";
    $(btnfive).addClass("btn");
    btn_five.appendChild(btnfive);
    row.appendChild(btn_five);
    $(btn_five).click(function(){
        //点击按钮触发事件
        $("#zone").innerHTML="";
        $("#ztwo").innerHTML="";
        $("#xuzu").modal('open');
        $("#xuzubtn").click(function(){
        
        var m=document.getElementById("zone").value;
        var n=document.getElementById("ztwo").value;
        var p;
        if(m=="月租"){
            p=1;
        }else{
            p=0;
        }
        var obj={
            orderId:orderid.innerHTML,
            dayOrMonth:p,
            rentalDay:n,
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/order/rerent",
            type: "get",
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(result){
               alert("续租成功！");
               window.open(result);
            }
        })
    })
    })
    
    //创建第六列订单先租后买button
    var btn_one = document.createElement('td');
    var btnone = document.createElement('button');
    btnone.innerHTML = "先租后买";
    $(btnone).addClass("btn");
    btn_one.appendChild(btnone);
    row.appendChild(btn_one);
    
    $(btn_one).click(function(){
        //点击按钮触发事件
        var r=confirm("确认购买此租用产品");
        if(r==false){
            return;
        }else{
        var obj={
            orderId:orderid.innerHTML
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/order/BuyAfterRent",//调用先租后买接口支付接口
            type: "get",
            
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(result){
                console.log(result);
                //window.location.href=result;
                window.open(result);
               
            }
        }) 
    }
    })

    //创建退货按钮
    var btn_two = document.createElement('td');
    var btntwo = document.createElement('button');
    btntwo.innerHTML = "退货";
    $(btntwo).addClass("btn");
    btn_two.appendChild(btntwo);
    row.appendChild(btn_two);
    $(btn_two).click(function(){
        //点击按钮触发事件
        var r=confirm("确认退货");
        if(r==false){
            return;
        }else{
        var reason=prompt("请输入退货原因！");
        //var reason=a.toString();   
        var obj={
            orderId:orderid.innerHTML,
            remark:reason
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/returnForm/returnProduct",//调用退货接口
            type: "get",
            
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(){
                alert("请点击正在租用以刷新订单状态！");
            }
        }) 
    }
    })

    //创建到期寄回
    var btn_three = document.createElement('td');
    var btnthree = document.createElement('button');
    btnthree.innerHTML = "到期寄回";
    $(btnthree).addClass("btn");
    btn_three.appendChild(btnthree);
    row.appendChild(btn_three);
    $(btn_three).click(function(){
        //点击按钮触发事件
            $('#my-alert-three').modal('open');
            var obj={
                orderId:orderid.innerHTML
            }
            console.log(obj);
            $.ajax({
                url: "http://8.130.103.251:8080/addressMes/getMes",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                  var a=order.userName;
                  var b=order.address;
                  //console.log(order.address);
                  var c=order.phoneNumber;
                  $("#ppone").html("商家："+a);
                  $("#pptwo").html("商家地址："+b);
                  $("#ppthree").html("商家号码："+c);
                }
            }) 
        
        }) 
    
    

    //创建确认寄回
    var btn_four = document.createElement('td');
    var btnfour = document.createElement('button');
    btnfour.innerHTML = "确认寄回";
    $(btnfour).addClass("btn");
    btn_four.appendChild(btnfour);
    row.appendChild(btn_four);
    $(btn_four).click(function(){
        //点击按钮触发事件
        $(btn_four).click(function(){
            //点击按钮触发事件
            var obj={
                orderId:orderid.innerHTML
            }
            console.log(obj);
            $.ajax({
                url: "http://8.130.103.251:8080/order/guihuanhuowu",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(){

                  alert("请等待商家确认！");
                }
            }) 
        
        }) 
    
    })
    //返回创建的行
    return row;

}

//添加先租后买功能（点击租用）
    $(document).ready(function(){
        $("#three").click(function(){
            var obj={
                user:getCookie("username"),
                //user:"zhangjian",
                shipStatus:"使用中",
            }
            // console.log(document.cookie);
            console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/order/getBuyOrder",
                type: "get",
                
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    
                    var tbody = document.getElementById('tbodythree');
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getDataRow方法,返回tr行数据
                        var trow = getButtonRow(order[i]); 
                        tbody.appendChild(trow);

                    }
                }
            })
            
})
})

//点击待商家确认
$(document).ready(function(){
    $("#seven").click(function(){
        var obj={
            user:getCookie("username"),
            //user:"zhangjian",
            shipStatus:"待确认",
        }
        console.log(obj);
        //console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/order/getBuyOrder",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    var tbody = document.getElementById('tbodyseven');
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getDataRow方法,返回tr行数据
                        var trow = getDataRow(order[i]); 
                        tbody.appendChild(trow);
                    }
                }
            })
    })
})

//点击结束
$(document).ready(function(){

      //读取登录状态
      var if_login=$.cookie("status");
      //读取用户名
      var username=$.cookie("username");
      
      if(if_login==1){
          $("#login_region").text(username);
          $("#dropdown-login-item").css("display","none");
          $("#dropdown-exit-item").css("display","block");
          
      }else if(if_login==0){
          $("#login_region").text("登录/注册");
          $("#dropdown-login-item").css("display","block");
          $("#dropdown-exit-item").css("display","none");
      }

    $("#four").click(function(){
        var obj={
            user:getCookie("username"),
            //user:"zhangjian",
            shipStatus:"已结束",
        }
        // console.log(document.cookie);
        console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/order/getBuyOrder",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    var tbody = document.getElementById('tbodyfour');
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getDataRow方法,返回tr行数据
                        var trow = getDataRow(order[i]); 
                        tbody.appendChild(trow);
                    }
                }
            })
    })
})



//点击售后
$(document).ready(function(){
    $("#six").click(function(){
        var obj={
            purchaser:getCookie("username"),
            //user:"zhangjian",
            status:"待商家处理",
        }
         console.log(obj);
        console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/returnForm/getBReturnForm",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    var tbody = document.getElementById('chuli');
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getDataRow方法,返回tr行数据
                        var trow = getChuliRow(order[i]); 
                        tbody.appendChild(trow);
                    }
                }
            })
    })
})

//函数getChuliRow用于创建待商家处理
function getChuliRow(result){
    //创建行
    var row = document.createElement('tr');
    //创建第一列订单号
    var orderid = document.createElement('td');
    orderid.innerHTML = result.orderId;
    row.appendChild(orderid);
    //创建第二列申请退货原因
    var remark = document.createElement('td');
    remark.innerHTML = result.remark;
    row.appendChild(remark); 
    //创建第三列订单详情按钮
    var btn = document.createElement('td');
    var btn_ = document.createElement('button');
    btn_.innerHTML = "查看订单详情";
    $(btn_).addClass("btn");
    btn.appendChild(btn_);
    row.appendChild(btn);
    //添加按钮点击事件
    $(btn).click(function(){
        // $("#my-alert").modal();
        // $("#my-alert").removeClass("am-modal");
        $('#my-alert-one').modal('open');
        var obj={
            orderId:orderid.innerHTML
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/order/getOrderById",
            type: "get",
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(order){
                console.log("a");
                var a=order.productName;
                var b=order.seller;
                var c=order.rental;
                var d=order.num;
                $("#pone").html("商品："+a);
                $("#ptwo").html("商家："+b);
                $("#pthree").html("租金："+c);
                $("#pfour").html("购买数量："+d);
            }
        })
    })
    //返回创建的行
    return row;

}

//函数getTuihuiRow用于创建含确认退回button的行
function getTuihuiRow(result){
    //创建行
    var row = document.createElement('tr');
    //创建第一列订单号
    var orderid = document.createElement('td');
    orderid.innerHTML = result.orderId;
    row.appendChild(orderid);
    //创建第二列我要退回button
    var btn_two = document.createElement('td');
    var btntwo = document.createElement('button');
    btntwo.innerHTML = "我要退回";
    $(btntwo).addClass("btn");
    btn_two.appendChild(btntwo);
    row.appendChild(btn_two);
    $(btn_two).click(function(){
        //点击按钮触发事件
        $('#my-alert-two').modal('open');
        var obj={
            orderId:orderid.innerHTML
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/returnForm/getAddress",
            type: "get",
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(order){
              var a=order.userName;
              var b=order.address;
              console.log(order.address);
              var c=order.phoneNumber;
              $("#pppone").html("商家："+a);
              $("#ppptwo").html("商家地址："+b);
              $("#pppthree").html("商家号码："+c);
            }
        }) 
    
    })
    //创建第三列确认退回button
    var btn_one = document.createElement('td');
    var btnone = document.createElement('button');
    btnone.innerHTML = "确认退回";
    $(btnone).addClass("btn");
    btn_one.appendChild(btnone);
    row.appendChild(btn_one);
    $(btn_one).click(function(){
        //点击按钮触发事件
        var r=confirm("确认已经退回？");
        if(r==false){
            return;
        }else{
        var obj={
            orderId:orderid.innerHTML,
            status:"待确认",
        }
        console.log(obj);
        $.ajax({
            url: "http://8.130.103.251:8080/returnForm/chulituihuo",
            type: "get",
            data: obj,
            contentType: 'application/json;charset=utf-8',
            success : function(){
              alert("请点击“待用户退回”以刷新订单状态！");
            }
        }) 
    }
    })
    //返回创建的行
    return row;
}


//函数getQuerenRow用于创建行
function getQuerenRow(result){
    //创建行
    var row = document.createElement('tr');
    //创建第一列租物名称
    var name = document.createElement('td'); 
    name.innerHTML = result.productName; //填充数据
    row.appendChild(name); //加入行
    //创建第二列订单号
    var orderid = document.createElement('td');
    orderid.innerHTML = result.orderId;
    row.appendChild(orderid);
    //创建第三列商家
    var seller = document.createElement('td');
    var btn_chat = document.createElement('button');
    btn_chat.innerHTML = result.seller;
    seller.addEventListener("click", funcjump.bind(seller, result.seller));
    $(btn_chat).addClass("btn");
    seller.appendChild(btn_chat);
    row.appendChild(seller);
    //创建第四列租金
    var money = document.createElement('td');
    money.innerHTML = result.rental;
    row.appendChild(money); 
    //创建第五列订单创建时间
    var begintime = document.createElement('td');
    begintime.innerHTML = result.makeTime;
    row.appendChild(begintime); 
    //返回创建的行
    return row;

}

//切换售后状态
$(document).ready(function(){
    $("#daichuli").click(function(){
        $("#daiqueren").removeClass("am-active choose_color");
        $("#daituihui").removeClass("am-active choose_color");
        $("#daichuli").addClass("am-active choose_color");
        //$("#daichuli").addClass("choose_color");
        $("#second").hide();
        $("#third").hide();
        $("#first").show();
        var obj={
            purchaser:getCookie("username"),
            //user:"zhangjian",
            status:"待商家处理",
        }
        // console.log(document.cookie);
        console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/returnForm/getBReturnForm",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    var tbody = document.getElementById('chuli');
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getDataRow方法,返回tr行数据
                        var trow = getChuliRow(order[i]); 
                        tbody.appendChild(trow);
                    }
                }
            })
    })

    $("#daituihui").click(function(){
        $("#daiqueren").removeClass("am-active choose_color");
        $("#daichuli").removeClass("am-active choose_color");
        $("#daituihui").addClass("am-active choose_color");
        $("#second").show();
        $("#third").hide();
        $("#first").hide();
        var obj={
            purchaser:getCookie("username"),
            //user:"zhangjian",
            status:"待买家寄回",
        }
        // console.log(document.cookie);
        console.log(getCookie("username"));
        $.ajax({
                url: "http://8.130.103.251:8080/returnForm/getBReturnForm",
                type: "get",
                data: obj,
                contentType: 'application/json;charset=utf-8',
                success : function(order){
                    console.log(order);
                    var tbody = document.getElementById('tuihui');
                    $(tbody).html("");
                    //遍历后端数据  
                    for(var i = 0;i < order.length; i++){ 
                    //定义getDataRow方法,返回tr行数据
                        var trow = getTuihuiRow(order[i]); 
                        tbody.appendChild(trow);
                    }
                }
            })
    })

    $("#daiqueren").click(function(){
        $("#daiqueren").addClass("am-active choose_color");
        $("#daichuli").removeClass("am-active choose_color");
        $("#daituihui").removeClass("am-active choose_color");
        $("#second").hide();
        $("#third").show();
        $("#first").hide();
        var obj={
            purchaser:getCookie("username"),
            //user:"zhangjian",
            status:"待确认",
        }
        // console.log(document.cookie);
        console.log(getCookie("username"));
                $.ajax({
                    url: "http://8.130.103.251:8080/returnForm/getBReturnForm",
                    type: "get",
                    data: obj,
                    contentType: 'application/json;charset=utf-8',
                    success : function(result){
                        console.log(result);
                        var order=[];
                        //order.push(result[k].orderId);
                        for(var j=0,k=0;k<result.length;j++,k++){
                            order[j]=result[k].orderId;
                            $.ajax({
                                url: "http://8.130.103.251:8080/order/getOrderById",
                                type: "get",
                                data: {
                                    orderId:order[j],
                                },
                                contentType: 'application/json;charset=utf-8',
                                success : function(order){
                                    console.log(order);
                                    var tbody = document.getElementById('queren');
                                    //console.log(order.length);
                                    $(tbody).html("");
                                    
                                    //遍历后端数据  
                                    //for(var i = 0;i < order.length; i++){ 
                                    //定义getDataRow方法,返回tr行数据
                                        console.log("zhixing");
                                        var trow = getQuerenRow(order); 
                                        
                                        tbody.appendChild(trow);
                                    
                                }
                            })
                        }
                        //console.log(order);
                        
                    
                    }
                })
            
        
       
    })
})

//导航栏顶部跳转数码专区
$("#digital-area").click(function(){
    $.cookie('pro_type',"数码配件",{ expires: 7 });
    window.open("tags.html");
});

//退出按钮的点击事件
$("#dropdown-exit-item").on("click",function () { 
    console.log("点击退出按钮");
    $.cookie('username', null);
    $.cookie('status', '0', { expires: 7 });
    location.reload ();
})



